/**
 * Copyright (C)
 * FileName: ItemServiceImpl
 * Author:   86151
 * Date:     2019/7/19 14:02
 * Description:
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.hand.llq25404.service.impl;

import com.hand.llq25404.entity.SsmItem;
import com.hand.llq25404.mapper.IItemMapper;
import com.hand.llq25404.service.IItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class ItemServiceImpl implements IItemService {

    @Autowired
    private IItemMapper iItemMapper;
    @Override
    public List<SsmItem> pagingQuery(int start, int pageSize) {
        return iItemMapper.pagingQuery(start,pageSize);
    }

    @Override
    public List<SsmItem> getSsmItems() {
        return iItemMapper.getSsmItems();
    }

    @Override
    public void addItem(SsmItem ssmItem) {
        //查询最大的物料编码
        String str = iItemMapper.maxItem();
        String item = str.substring(0,4);
        int num = Integer.parseInt(str.substring(5));
        num ++;
        int n = num;
        int i = 0;
        while(n > 0){
            n = n/10;
            i ++;
        }
        for(;i<10;i ++){
            item = item + "0";
        }
        item = item + num + "";
        ssmItem.setItemCode(item);
        System.out.println(item);
        System.out.println(ssmItem);
        iItemMapper.addItem(ssmItem);
    }

    @Override
    public void delItem(String itemId) {
        iItemMapper.delItem(itemId);
    }

    @Override
    public SsmItem queryId(Long itemId) {
        return iItemMapper.queryId(itemId);
    }

    @Override
    public void update(SsmItem ssmItem,long item_id) {
        SsmItem s = iItemMapper.queryId(item_id);
        ssmItem.setObjectVersionNumber(s.getObjectVersionNumber() + 1);
        iItemMapper.update(ssmItem,item_id);
    }

    @Override
    public List<SsmItem> getCount(SsmItem ssmItem) {
        return iItemMapper.getCount(ssmItem);
    }

    @Override
    public List<SsmItem> fuzzyQuery(int start, int pageSize, String itemCode, String itemDescription,String itemUom ,String startActiveDate, String endActiveDate, String enabledFlag) {
        return iItemMapper.fuzzyQuery(start,pageSize,itemCode,itemDescription,itemUom,startActiveDate,endActiveDate,enabledFlag);
    }

    @Override
    public List<SsmItem> getCount(String itemCode, String itemDescription, String itemUom, String startActiveDate, String endActiveDate, String enabledFlag) {
        return iItemMapper.getCount(itemCode,itemDescription,itemUom,startActiveDate,endActiveDate,enabledFlag);
    }

}